﻿CREATE PROCEDURE dbo.smenu_Tracker_Send
(	@Counter int,
	@Dir int -- 1 - Next, -1 - Previous, 0 - Anywhere, NULL - Back
)
AS
SET NOCOUNT ON

BEGIN TRAN

DECLARE @TrackerID varchar(11) SELECT @TrackerID = ID FROM t_Tracker WHERE Counter = @Counter

UPDATE t_Tracker SET StatusID = dbo.NextTrackerStatus(@TrackerID, @Dir) WHERE ID = @TrackerID

IF @@ROWCOUNT <= 1 AND @@ERROR = 0 BEGIN COMMIT TRAN RETURN END

IF @@ERROR <> 0 RETURN

RAISERROR('Tracker %s has more than one path in %d direction.',16,1,@TrackerID,@Dir)
ROLLBACK TRAN

